home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 May / EnigmA AMIGA RUN 07 (1996)(G.R. Edizioni)(IT)[!][issue 1996-05][EARSAN CD VI].iso / progs / utilmisc / frontpub / frontpub_asm / frontpub.s < prev    next >
Text File  |  1995-03-27  |  8KB  |  335 lines

  1. ***************************************************************************
  2.  
  3. ; frontpub v1.0 - 16/01/95 by Gunther Nikl - initial version
  4. ; frontpub v1.0 - 25/03/95 by Gunther Nikl - CheckFrontScr() rewritten
  5.  
  6. ***************************************************************************
  7.  
  8. ; include stuff
  9.  
  10.         include    exec/types.i
  11.         include    lvo30/dos_lib.i
  12.         include    lvo30/exec_lib.i
  13.         include    lvo30/intuition_lib.i
  14.         include    lvo30/commodities_lib.i
  15.  
  16. CALL        MACRO
  17.         move.l    \2,a6
  18.         jsr    _LVO\1(a6)
  19.         ENDM
  20.  
  21. RECALL        MACRO
  22.         jsr    _LVO\1(a6)
  23.         ENDM
  24.  
  25. ; global stuff
  26.  
  27.     STRUCTURE Globals,0
  28.       ULONG SysBase
  29.       ULONG WbMsg
  30.       ULONG IntBase
  31.       ULONG CxBase
  32.       ULONG FrontScr
  33.       ULONG Broker
  34.       UBYTE CxEnable
  35.       UBYTE CheckIt
  36.       UBYTE IntrSig
  37.       UBYTE Pad1
  38.       STRUCT NewBroker,26
  39.       STRUCT ScrIntr,22
  40.     LABEL gb_SIZEOF
  41.  
  42. BrokerPort    equ    NewBroker+20
  43.  
  44. bp        equr    a4            ; the base register
  45.  
  46. ***************************************************************************
  47.  
  48.         SECTION start,CODE
  49.  
  50. start        moveq    #(gb_SIZEOF>>2)-1,d0
  51. 1$        clr.l    -(sp)            ; clear local var area
  52.         dbra    d0,1$
  53.         move.l    sp,bp
  54.         move.l    4,a6
  55.         move.l    a6,SysBase(bp)        ; cache SysBase
  56.         suba.l    a1,a1
  57.         RECALL    FindTask        ; use system function ..
  58.         move.l    d0,a2
  59.         tst.l    172(a2)
  60.         bne.s    fromCLI
  61. fromWB        lea    92(a2),a0        ; get wbmsg
  62.         RECALL    WaitPort
  63.         lea    92(a2),a0
  64.         RECALL    GetMsg
  65.         move.l    d0,WbMsg(bp)
  66. fromCLI        bsr    main            ; call main
  67.         move.l    WbMsg(bp),d2
  68.         beq.s    1$
  69.         RECALL    Forbid
  70.         move.l    d2,a1
  71.         RECALL    ReplyMsg        ; reply wbsmg
  72. 1$        moveq    #0,d0
  73.         lea    gb_SIZEOF(bp),sp
  74.         rts
  75.  
  76. ***************************************************************************
  77.  
  78. InstallCx    CALL    CreateMsgPort,SysBase(bp) ; init & install broker
  79.         move.l    d0,BrokerPort(bp)
  80.         beq.s    1$            ; no port ...
  81.         lea    NewBroker(bp),a1
  82.         move.w    #$500,(a1)+
  83.         lea    ProgName(pc),a0
  84.         move.l    a0,(a1)+
  85.         lea    Version(pc),a0
  86.         move.l    a0,(a1)+
  87.         lea    Description(pc),a0
  88.         move.l    a0,(a1)+
  89.         move.w    #1,(a1)
  90.         lea    NewBroker(bp),a0
  91.         moveq    #0,d0
  92.         CALL    CxBroker,CxBase(bp)
  93.         move.l    d0,Broker(bp)
  94.         beq.s    1$            ; no broker ...
  95.         move.l    d0,a0
  96.         moveq    #1,d0
  97.         RECALL    ActivateCxObj
  98.         moveq    #1,d0            ; all ok !
  99.         move.b    d0,CxEnable(bp)
  100. 1$        rts
  101.  
  102. ***************************************************************************
  103.  
  104. OpenLibs    move.l    SysBase(bp),a6        ; open all libs!
  105.         lea    IntName(pc),a1
  106.         moveq    #37,d0
  107.         RECALL    OpenLibrary
  108.         move.l    d0,IntBase(bp)
  109.         beq.s    3$            ; no intuition v37+ !
  110.         lea    CxName(pc),a1
  111.         moveq    #37,d0
  112.         RECALL    OpenLibrary
  113.         move.l    d0,CxBase(bp)
  114.         bne.s    1$            ; commodities v37+ ok ! 
  115. 3$        tst.l    WbMsg(bp)
  116.         bne.s    2$
  117.         lea    DosName(pc),a1
  118.         moveq    #0,d0
  119.         RECALL    OpenLibrary
  120.         move.l    d0,d6
  121.         beq.s    2$            ; no dos ...
  122.         exg    d6,a6
  123.         RECALL    Output
  124.         move.l    d0,d1
  125.         lea    NeedV37(pc),a2
  126.         move.l    a2,d2
  127.         moveq    #NeedV37len,d3
  128.         RECALL    Write            ; osversion message
  129.         exg    d6,a6
  130.         move.l    d6,a1
  131.         RECALL    CloseLibrary
  132. 2$        moveq    #0,d0
  133. 1$        rts
  134.  
  135. ***************************************************************************
  136.  
  137. main        movem.l    d2-d7/a2-a6,-(sp)    ; main program
  138.         bsr.s    OpenLibs
  139.         beq    1$
  140.         bsr    InstallCx
  141.         beq    1$
  142.         moveq    #-1,d0
  143.         CALL    AllocSignal,SysBase(bp)    ; allocate intr-signal
  144.         move.b    d0,IntrSig(bp)
  145.         bmi.s    1$
  146.         moveq    #0,d0
  147.         CALL    SetPubScreenModes,IntBase(bp)
  148.         moveq    #1,d1
  149.         or.w    d0,d1
  150.         move.l    d1,d0
  151.         RECALL    SetPubScreenModes
  152.         lea    ScrIntr+8(bp),a1    ; init & install intr-server
  153.         move.w    #$2ff,(a1)+
  154.         lea    ProgName(pc),a0
  155.         move.l    a0,(a1)+
  156.         move.l    bp,(a1)+
  157.         lea    ScrHandler(pc),a0
  158.         move.l    a0,(a1)
  159.         lea    ScrIntr(bp),a1
  160.         moveq    #5,d0
  161.         CALL    AddIntServer,SysBase(bp)
  162.         st    CheckIt(bp)
  163. 4$        moveq    #$40,d0            ; build wait mask
  164.         lsl.w    #6,d0
  165.         move.b    IntrSig(bp),d1
  166.         bset    d1,d0
  167.         move.l    BrokerPort(bp),a1
  168.         move.b    15(a1),d1
  169.         bset    d1,d0
  170.         RECALL    Wait
  171.         btst    #12,d0
  172.         bne.s    2$            ; got CTRL_C !
  173.         move.b    IntrSig(bp),d1
  174.         btst    d1,d0
  175.         beq.s    3$            ; no signal from interrupt
  176.         bsr    CheckFrontScr
  177. 3$        bsr    CheckBroker
  178.         beq.s    4$            ; no end request from Exchange
  179. 2$        lea    ScrIntr(bp),a1
  180.         moveq    #5,d0
  181.         RECALL    RemIntServer        ; remove intr-server
  182. 1$        bsr.s    RemoveCx
  183.         bsr.s    CloseLibs
  184.         movem.l (sp)+,d2-d7/a2-a6    ; exit main
  185.         rts
  186.  
  187. ***************************************************************************
  188.  
  189. CloseLibs    move.l    SysBase(bp),a6        ; close all libs
  190.         move.l    CxBase(bp),a1
  191.         bsr.s    2$
  192.         move.l    IntBase(bp),a1
  193. 2$        move.l    a1,d0
  194.         beq.s    1$
  195.         RECALL    CloseLibrary
  196. 1$        rts
  197.  
  198. ***************************************************************************
  199.  
  200. RemoveCx    move.l    Broker(bp),d2        ; free commodity stuff
  201.         beq.s    2$
  202.         move.l    d2,a0
  203.         moveq    #0,d0
  204.         CALL    ActivateCxObj,CxBase(bp)
  205.         move.l    d2,a0
  206.         RECALL    DeleteCxObjAll
  207. 2$        move.l    BrokerPort(bp),d0
  208.         beq.s    1$
  209.         move.l    d0,a0
  210.         CALL    DeleteMsgPort,SysBase(bp)
  211. 1$        rts
  212.  
  213. ***************************************************************************
  214.  
  215. CheckBroker    movem.l    d2/a2/a6,-(sp)
  216.         moveq    #0,d2            ; quit:=false
  217. 4$        move.l    BrokerPort(bp),a0    ; check port
  218.         CALL    GetMsg,SysBase(bp)
  219.         move.l    d0,a2
  220.         move.l    a2,d0
  221.         beq.s    1$            ; no message
  222.         move.l    a2,a0
  223.         CALL    CxMsgType,CxBase(bp)
  224.         cmpi.w    #$40,d0            ; CXM_COMMAND
  225.         bne.s    2$
  226.         move.l    a2,a0
  227.         RECALL    CxMsgID
  228. ;        cmp.w    #25,d0            ; CXCMD_UNIQUE
  229. ;        beq.s    2$
  230.         cmpi.w    #23,d0            ; CXCMD_KILL
  231.         seq    d2
  232.         beq.s    2$
  233.         moveq    #1,d1
  234.         cmpi.w    #17,d0            ; CXCMD_ENABLE
  235.         beq.s    3$
  236.         moveq    #0,d1
  237.         cmpi.w    #15,d0            ; CXCMD_DISABLE
  238.         bne.s    2$
  239. 3$        move.b    d1,CxEnable(bp)
  240.         move.l    d1,d0
  241.         move.l    Broker(bp),a0
  242.         RECALL    ActivateCxObj        ; enable or disable broker
  243. 2$        move.l    a2,a1
  244.         CALL    ReplyMsg,SysBase(bp)    ; reply message
  245.         bra.s    4$
  246. 1$        move.l    d2,d0            ; return 'quit'
  247.         movem.l    (sp)+,d2/a2/a6
  248.         rts
  249.  
  250. ***************************************************************************
  251.  
  252. CheckFrontScr    move.l    a6,-(sp)
  253.         move.l    a2,-(sp)
  254.         link    a5,#-144
  255.         CALL    Forbid,SysBase(bp)    ; disable multitasking
  256.         moveq    #0,d0
  257.         CALL    LockIBase,IntBase(bp)
  258.         move.l    d0,a0
  259.         RECALL    UnlockIBase
  260.         RECALL    LockPubScreenList    ; get pubscreen list
  261.         move.l    d0,a2
  262.         move.l    sp,a0            ; namebuf for defpubscr name
  263.         RECALL    GetDefaultPubScreen
  264.         move.l    a2,a0
  265.         move.l    sp,a1
  266.         CALL    FindName,SysBase(bp)    ; screen in the list ?
  267.         move.l    d0,a0
  268.         move.l    a0,d0
  269.         move.l    IntBase(bp),a6
  270.         beq.s    2$
  271.         move.l    60(a6),d0
  272.         move.l    d0,FrontScr(bp)
  273.         cmp.l    14(a0),d0        ; is the screen the firstscreen ?
  274.         beq.s    2$
  275. 4$        move.l    0(a2),a2        ; check if frontscr is a pubscreen
  276.         tst.l    0(a2)
  277.         beq.s    2$
  278.         cmp.l    14(a2),d0
  279.         bne.s    4$
  280.         btst    #0,19(a2)
  281.         bne.s    2$
  282.         move.l    10(a2),a0        ; copy name of public screen
  283.         move.l    sp,a1
  284. 3$        move.b    (a0)+,(a1)+        ; for the sake of safety :)
  285.         bne.s    3$
  286.         suba.l    a2,a2
  287. 2$        RECALL    UnlockPubScreenList
  288.         move.l    a2,d0
  289.         bne.s    1$
  290.         move.l    sp,a0            ; frontscr becomes default pubscr
  291.         RECALL    SetDefaultPubScreen
  292. 1$        CALL    Permit,SysBase(bp)    ; enable multitasking
  293.         st    CheckIt(bp)        ; enable interrupt checking
  294.         unlk    a5
  295.         move.l    (sp)+,a2
  296.         move.l    (sp)+,a6
  297.         rts
  298.  
  299. ***************************************************************************
  300.  
  301. ScrHandler    move.b    CxEnable(a1),d0        ; commodity on ?
  302.         add.b    CheckIt(a1),d0
  303.         bne.s    1$
  304.         move.l    IntBase(a1),a0
  305.         move.l    60(a0),d0
  306.         beq.s    1$            ; no screen !?
  307.         cmp.l    FrontScr(a1),d0
  308.         beq.s    1$            ; IntBase->FirstScreen != FrontScr
  309.         clr.b    CheckIt(a1)
  310.         move.l    SysBase(a1),a6
  311.         moveq    #0,d0
  312.         move.b    IntrSig(a1),d1
  313.         bset    d1,d0
  314.         move.l    BrokerPort(a1),a1
  315.         move.l    16(a1),a1
  316.         RECALL    Signal            ; wakeup our task
  317. 1$        moveq    #0,d0
  318.         rts
  319.  
  320. ***************************************************************************
  321.  
  322. ; static data
  323.  
  324.         dc.b    '$VER: '
  325. Version        dc.b    'FrontPub 1.1 (25.3.95) © 1995 by G.Nikl',0
  326. Description    dc.b    'frontmost pubscreen becomes default',0
  327. ProgName    dc.b    'FrontPub',0
  328. DosName        dc.b    'dos.library',0
  329. IntName        dc.b    'intuition.library',0
  330. CxName        dc.b    'commodities.library',0
  331. NeedV37        dc.b    'This program requires at least v37 of the OS!',10,0
  332. NeedV37len    equ    *-NeedV37-1
  333.  
  334.         end
  335.